package com.yugao.fintech.antelope.codegen.service.impl;

import com.yugao.fintech.antelope.codegen.assembly.GenTableAssembly;
import com.yugao.fintech.antelope.codegen.manager.GenTableColumnManager;
import com.yugao.fintech.antelope.codegen.model.entity.GenTableColumn;
import com.yugao.fintech.antelope.codegen.model.rqrs.GenTableColumnRS;
import com.yugao.fintech.antelope.codegen.service.GenTableColumnService;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class GenTableColumnServiceImpl implements GenTableColumnService {
    @Autowired
    private GenTableColumnManager genTableColumnManager;
    @Autowired
    private GenTableAssembly genTableAssembly;

    @Override
    public List<GenTableColumnRS> listGenTableColumnByTableId(Long tableId) {
        List<GenTableColumn> list = genTableColumnManager.listByTableId(tableId);
        return list.stream().map(genTableAssembly::toGenTableColumnRS).collect(Collectors.toList());
    }

    @Override
    public void deleteGenTableColumnByIds(List<Long> ids) {
        if (!genTableColumnManager.removeByIds(ids)) {
            throw new BizException("删除失败");
        }
    }
}
